<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>编辑菜单</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__UI__/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="__UI__/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <link rel="stylesheet" href="__UI__/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <input type="hidden" name="id" value="{$row.id}">
    <div class="layui-form-item">
        <label class="layui-form-label required">父ID</label>
        <div class="layui-input-block">
            <!--<input type="text" name="pid" lay-verify="required" lay-reqtext="父ID不能为空" placeholder="请输入父ID" value="{$row.pid}" class="layui-input">-->
            <input type="text" id="pid" name="pid" lay-filter="pid" class="layui-input" lay-verify="required" lay-reqtext="父ID不能为空" value="{$row.pid}" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">菜单名称</label>
        <div class="layui-input-block">
            <input type="text" name="title" lay-verify="required" lay-reqtext="菜单名称不能为空" placeholder="请输入菜单名称" value="{$row.title}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">菜单图标</label>
        <div class="layui-input-block">
            <input type="text" id="icon" name="icon" value="{$row.icon}"  class="hide" lay-filter="icon">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">链接</label>
        <div class="layui-input-block">
            <input type="text" name="href" placeholder="请输入链接" value="{$row.href}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">打开方式</label>
        <div class="layui-input-block">
            <select name="target">
                <option value="_self" {if $row.target=='_self'}selected{/if}>_self</option>
                <option value="_blank" {if $row.target=='_blank'}selected{/if}>_blank</option>
                <option value="_parent" {if $row.target=='_parent'}selected{/if}>_parent</option>
                <option value="_top" {if $row.target=='_top'}selected{/if}>_top</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">排序值</label>
        <div class="layui-input-block">
            <input type="number" name="sort" placeholder="请输入排序值" value="{$row.sort}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">状态</label>
        <div class="layui-input-block">
            <input type="radio" name="status" value="1" title="启用" {if $row.status==1}checked{/if}>
            <input type="radio" name="status" value="0" title="禁用" {if $row.status!=1}checked{/if}>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">备注信息</label>
        <div class="layui-input-block">
            <textarea name="remark" class="layui-textarea" placeholder="请输入备注信息">{$row.remark}</textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="__UI__/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="__UI__/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="__UI__/js/common.js" charset="utf-8"></script>
<script>
    layui.use(['form','iconPickerFa','treeSelect'], function () {
        var form = layui.form,
            layer = layui.layer,
            iconPickerFa = layui.iconPickerFa,
            treeSelect= layui.treeSelect,
            $ = layui.$;

        treeSelect.render({
            elem: '#pid',  // 选择器
            data: '{:url("admin/menu/getTreeList")}',// 数据
            headers: {},// 请求头
            type: 'post',// 异步加载方式：get/post，默认get
            placeholder: '请选择父级菜单',// 占位符
            success: function (d) {
                treeSelect.checkNode('pid', {$row.pid});//选中节点，根据id筛选
                treeSelect.zTree('pid').expandAll(true);
            }
        });

        iconPickerFa.render({
            elem: '#icon',
            url: "__UI__/lib/font-awesome-4.7.0/less/variables.less",
            limit: 12,
            search:true,
            click: function (data) {
                $('#icon').val('fa ' + data.icon);
            },
            success: function (d) {
                //console.log(d);
            }
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            data = data.field;
            postSubmit(
                $,
                "{:url('admin/menu/edit')}",
                data,
                function (res) {
                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(iframeIndex);
                    parent.layui.$('button[lay-event=reload]').click();//刷新表格的数据
                },  //请求成功时的处理
                function () {} //请求错误时的处理
            );


            return false;
        });

    });
</script>
</body>
</html>